package com.ourhours.message.common;

import lombok.Data;

/**
 * 统一返回结果
 */
@Data
public class BaseResult<T> {

    public static final String SUCCESS_CODE = "0000";
    public static final String ERROR_CODE = "-1";

    private String code;
    private String msg;
    private T data;

    public BaseResult(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public BaseResult(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> BaseResult<T> success() {
        return success("操作成功");
    }

    public static <T> BaseResult<T> success(String msg) {
        return new BaseResult<>(SUCCESS_CODE, msg );
    }

    public static <T> BaseResult<T> success(T obj) {
        BaseResult<T> success = success();
        success.setData(obj);
        return success;
    }

    public static <T> BaseResult<T> success(String msg, T obj) {
        return new BaseResult<>(SUCCESS_CODE, msg, obj);
    }

    public static <T> BaseResult<T> failure(String code, String msg) {
        return new BaseResult<>(code, msg);
    }

    public static <T> BaseResult<T> failure(String msg) {
        return new BaseResult<>("-1", msg);
    }

}
